package com.biye.auth.controller;

import com.biye.auth.tool.rabbitProvider.dao.HuoDongCourseDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.logging.Logger;

/**
 * @Author Maple.Chen
 * @Description 消息发布者接口
 * @Date 20:26 2021/3/1
 **/
@Controller
@EnableBinding({HuoDongCourseDao.class})
public class MessageProviderController {

    @Autowired
    private HuoDongCourseDao huoDongCourseDao;

    @GetMapping("/sendMessage")
    @ResponseBody
    public String messageWithMQ(@RequestParam(value = "message", required = false, defaultValue = "1") String message) {
        if(message.equals("1")){
            huoDongCourseDao.output1().send(MessageBuilder.withPayload("GOD " + message).setHeader("version", "1.0").build());
        }else if(message.equals("2")){
            huoDongCourseDao.output1().send(MessageBuilder.withPayload("BGM " + message).setHeader("version", "2.0").build());
        }
        return "消息已发送";
    }

}
